
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Auth extends CI_Controller {
	
	public function login(){
        $this->load->library('form_validation');//加载表单验证类
        //$this->form_validation->set_error_delimiters('<div class="error">', '</div>');//全局的修改定界符
        $this->form_validation->set_rules('username', '用户名', 'required|min_length[3]|max_length[12]');
		$this->form_validation->set_rules('password', '密码', 'required|callback__auth_check');
        if ($this->form_validation->run() == FALSE){
            $this->load->view('admin/login');
        }
        else {
            $this->session->set_userdata('is_login', true);
        	redirect('/admin/article/index');
        }
	}
	public function _auth_check(){
		$this->load->model("Admin_model");
		$username = $this->input->post('username');
		$password = md5($this->input->post('password'));
        if ($this->Admin_model->get_one($username,$password)){
            return TRUE;
        }else{
            $this->form_validation->set_message('_auth_check', '用户名密码不正确');
            return FALSE;
        }
    }
}
